This invention relates to the data processing field. More specifically, this invention relates to Object Oriented Programming environments.
The development of the EDVAC computer system of 1948 is often cited as the beginning of the computer era. Since that time, computer systems have found their way into just about every aspect of the American life style. One reason for this proliferation is the ability of computer systems to perform a variety of tasks in an efficient manner. The mechanisms used by computer systems to perform these tasks are called computer programs.
Like computer systems themselves, the development of computer programs has evolved over the years. The EDVAC system used what was called a xe2x80x9cone addressxe2x80x9d computer programming language. This language allowed for only the most rudimentary computer programs. By the early 1950s, scientists had developed mechanisms which could convert symbolic instructions that were reasonably understandable to humans into a form which could be understood by a computer system. Each computer system was designed to handle a specific group of these instructions. These groups of instructions are called instruction sets.
The next step in the development of computer programs was the notion of computer programming languages. Computer programming languages were even more understandable than symbolic instruction sets. Computer programs are written using a variety of computer programming languages. Once written, a computer program is compiled into instructions that are part of the instruction set of a particular computer system. FORTRAN is usually cited as one of the first languages to allow computer programs to be written independently of a particular instruction set. By the 1960s, improvements in computer programming languages led to computer programs that were so large and complex that it was difficult to manage and control their development and maintenance.
Hence, in the 1970s, focus was directed away from developing new programming languages towards the development of programming methodologies and environments which could better accommodate the increasing complexity and cost of large computer programs. One such methodology is the Object Oriented Programming (OOP) approach. OOP advocates claim that this approach to computer programming can improve the productivity of computer programmers by as much as twenty-five fold. Hence, while it has been some time since the OOP concept was originally developed, it is currently seen as the way of the future.
The two fundamental concepts of OOP are xe2x80x9cencapsulationxe2x80x9d and xe2x80x9creusability.xe2x80x9d Encapsulation means that information and the means for using the information are conceptually packaged into individual entities called xe2x80x9cobjects.xe2x80x9d The objects represent individual operations or groups of operations that can be performed by a computer system. The information contained in an object is called data and the means used to perform a particular operation upon the information is called a method. The idea of reusability is that the objects are made sufficiently generic so that they can be used by the methods of many other objects. Any program or method program that uses an object is said to be a client of that object (i.e., a client program). The client will call or invoke the object while specifying the method that is to be used. This is called method resolution.
Objects are also considered to be members of a particular xe2x80x9cclassxe2x80x9d of objects. When objects are created they may be members of a particular class or they may be considered to be members of a subclass of a particular class. Objects that are created as members of a subclass are said to have xe2x80x9cinheritedxe2x80x9d the characteristics (i.e., the data and methods) of the class to which they are a subclass (i.e., their super class). For example, consider a class of objects called Canine. The class will have data that describes objects of that class (i.e., name, colour, number of eyes and legs, etc.) The class will also have methods defined which can be used to work with the data of the class. For example, an object of class Canine could be an object that represented a canine named REX that was black and had two eyes and four legs. A subclass of class Canine, class Dog, could further define class Canine to include data that indicated what type of canine Was involved. For example, an object of class Dog could be created that represented a dog named Lassie that was white and brown, had two eyes, four legs, and was of type Collie. Class Canine would also, then, be considered a super class of class Dog. As objects and subclasses are added, a hierarchical tree structure is created. Each class, be it respectively referred to as a subclass or super class, is considered to be at a certain level in the hierarchical structure. In the example, class Dog, as a subclass of class Canine, would be at a level one greater than that of class Canine.
According to the present state of the art, e.g., the Interface Definition Language (IDL) or Microsoft""s COM (Common Object Model)/ActiveX/OLE (Object Linking and Embedding), when an object is being defined all of the methods which this object supports are embedded in a text file which is then used to generate Object Method templates.
It is very common to define one object (e.g., object AX) as containing other objects (e.g., objects B1 and B2). AX is then known as an object union of B1 and B2. When this is done, all of the methods that are publicly available in B1 and B2 become also publicly accessible from AX. That is, if object B1 supports methods m,n,o,p and object B2 supports methods k,l,m,n then an external object can make method calls on AX using the following methods: B1.m, B1.n, B1.o, B1.p, B2.k, B2.1, B2.m, B2.n. However, oftentimes it is advantageous to define AX so that only some of the B1 and/or B2 methods are publicly accessible via AX. For example, for reasons of security or performance it may be required that only methods whose names are common to B1 and B2 be publicly accessible via AX.
The usual way this restriction has been carried out according to the present state of the art is to create a subclass c1 of B1 and a subclass C2 of B2, such subclasses hiding the undesired implementations and methods. However, this involves a compile or definition time activity and thus the inventors have found that this includes inflexible limitations, such as a high degree of programming redundancy in order to obtain the desired methods.
Specifically, there are several areas of programming where such a dynamic inheritance is useful. Consider the case where an Object is to have different behaviours based on some criteria, for example, time. We call this object the DayNight Object which is instantiated from a Class called DayNightClass (the concept of Class Factories is not relevant to this discussion). The object has a given behaviour during working hours, but another behaviour during the night.
Under the OO programming technique now widely used, this Object would normally be instantiated from two different Classes: Day and Night. This would mean that two new Classes are setup, both inheriting from the DayNightClass: DayFromDayNightClass and NightFromDayNightClass; both of these derived Classes contain the same methodsxe2x80x94it is the implementation that differs. Thus, the application program has to instantiate a DayFromDayNightClass or a NightFromDayNightClass object.
The logic for determining whether a Day Object or a Night Object is to be instantiated, therefore, lies in the application that creates the Object. According to a pure view of the Object Oriented paradigm, this is the wrong place for a decision to be made about the function of the Objectxe2x80x94it is the Object itself that should determine its mode of operation. The present invention presents a technique for removing this corruption of the pure OO paradigm.
Another technique is to supply a parameter at instantiation time. This permits the instantiation of a DayNightClass object to always be performed, with the instantiation parameter being saved within the instantiated Object to govern subsequent behaviour. Again, this reduces the complexity of actually getting an Object to exhibit dynamic behaviour. The drawback with this technique is that it permits Objects to exhibit variable behaviours based on information captured at instantiation time, but then behaviour is fixed for the lifetime of the Object existence. This may be either a good thing or a bad thing depending upon what flavour of OO purity is adopted, but it presents an inflexible design and thus does not provide the degree of flexibility that the present invention addresses.
What is really required is a way for an Object to exhibit different behaviours based on decisions taken within the Object itself. The external environment may provide information or hints as to the operation, but it is up to the Object itself to determine its behaviour.
In the aforementioned DayNightClass, it is clearly better for an Object instantiated from the DayNightClass to decide whether it is running during the Day or the Night and alter it""s behaviour accordingly. This decision may be based on external information like the Time or TimeZone or Date (Night begins early on Friday and lasts until Monday morning), but the decision is made by the Object, not the instantiator.
It is even more desirable that when running during the Night, methods related purely to Daytime actions do not exist. The only way this can be performed is for these latter methods always to exist, but when being executed return a user-defined exception (or bad Return Code) during the Night. It would be much more desirable (from the viewpoint of application coding) if the method did not actually exist when it could not be executed. The present invention provides such a mechanism.
If we consider that an Object is making these sorts of decisions, it is clearly required for the Object itself to decide which functions are executed as the result of a method call. For example, if there was a public method called Charge then private versions called ChargeDay and ChargeNight would be provided. When the public Charge Method is invoked, then this Charge Method would dispatch the call to either the private ChargeNight or private ChargeDay method to do the calculation. This is the only currently workable way to accomplish execution of either ChargeDay or ChargeNight in response to the externally visible Charge method when the instantiated Object is making runtime execution decisions.
To accomplish the function in ChargeDay or ChargeNight, the DayNight Class has to inherit all of the associated requirements for both the ChargeDay and ChargeNight methods. This is a fixed requirement of the OO inheritance paradigm. Problems then arise if the inheritance requirements for ChargeDay conflict with those for ChargeNight. These commonly relate to namespace clashes (such as LHS and RHS inheritance as discussed later on), but can be more fundamental if actual implementation requirements require completely incompatible inheritance trees. In this case, the ChargeDay and ChargeNight private methods cannot be implemented within the same instantiated Object, and so the required function cannot be provided. This patent removes this restriction.
The OO inheritance design also has an implicit assumption that all publicly exposed methods are accessible by the user of the instantiated object. Any security processing that exists is performed at instantiation time (whether or nor the current user/security context can create the object) and it is left to the methods themselves to police accessibility when executed. This arrangement leads to a security exposure in that all the methods are available to a userxe2x80x94whereas what is required is that only methods available for execution are visible (unauthorised methods are not visible and so not discoverable).
This hiding of methods based on Security Context (or other information available at Object instantiation time) is not supported under current OO implementation. All public methods are always available. Consequently, there is a security exposure or an assumption that instantiation-time security is all that is needed. The present invention addresses this area and removes the security exposure.
Thus, the problem with current OO definitions is that inheritance and method visibility has to be fixed at compile (or Interface Definition Language) time, whereas what is required is that these decisions be postponed until execution time; and that this execution time decision is dynamic. By actually controlling the contents of an instantiated object whenever it is accessed the present invention provides the required degree of flexibility for security and functional purposes.
According to one aspect, the present invention provides a computer implemented method of defining an object union in an object oriented programming environment, comprising the steps of: selecting a first class from which a first object to be contained in the object union will be instantiated at runtime; selecting a second class from which a second object to be contained in the object union will be instantiated at runtime; selecting a policy function for operating on the first and second classes, at runtime, in order to define which methods supported by the first and second classes will be accessible via the object union at runtime.
According to a second aspect, the invention provides a computer program product, stored on a computer readable storage medium for, when run on a computer system, instructing the computer system to carry out the method steps of the first aspect.
According to a third aspect, the invention provides a data processing apparatus for carrying out the method steps of the first aspect.
Thus, with the present invention, an object union is defined, where the selection of which methods of the contained objects are accessible via the object union is made dynamically at runtime.